package com.ton.utils.tron.http;


import com.ton.utils.http.HttpUtils;
import com.ton.utils.http.RestTemplateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * TonscanAPI 继承自 HttpUtils 拥有 HttpUtils 主要方法
 * 本工具类用于Tonscan第三方接口查询
 * Tonscan官网：https://tonscan.org/
 * API引导：https://toncenter.com/
 * 主要用途：查询TON、ERC20交易记录、评论说明、账户余额等
 */
@Component
@Slf4j
public class TonscanAPI extends HttpUtils {
    /**
     * 主方法 GET
     * @param path 路径
     * @param params 参数
     * @return 字符串
     */
    public static String getToncenter(String path, Map<String, Object> params) {
        String baseUrl = "https://toncenter.com/api/v3/";
        Map<String, String> headers = new HashMap<>();
        headers.put("Accept", "*/*");
        return RestTemplateUtils.doGet(baseUrl + path, headers, params);
    }
    public static String getTonAPI(String path, Map<String, Object> params) {
        String baseUrl = "https://tonapi.io/v2/";
        Map<String, String> headers = new HashMap<>();
        headers.put("Accept", "*/*");
        return RestTemplateUtils.doGet(baseUrl + path, headers, params);
    }

    /**
     * 查询交易记录 limit 100条
     * @param address 地址
     * @return JSON
     */
    public static String getTransaction(String address){
        Map<String,Object> map =new HashMap<>();
        map.put("account",address);
        map.put("limit","100");
        String json = TonscanAPI.getToncenter("transactions", map);
        return json;
    }
    public static String getEvents(String address){
        Map<String,Object> map =new HashMap<>();
        map.put("limit","100");
        String json = TonscanAPI.getTonAPI("accounts/"+address+"/events", map);
        return json;
    }


//https://tonapi.io/v2/accounts/UQAxp7JMc1uNTO8mLdnmwzCLmqIRUTZhNvDsKHJIUedg_zaa/events?limit=100
}
